//
//  eye_hunterViewController.m
//  eye_hunter
//
//  Created by cherry on 10-9-24.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "eye_hunterViewController.h"

@implementation eye_hunterViewController

@synthesize hunterDB;
@synthesize missionView;
@synthesize scrollView;

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/


// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
	//1. init database
	hunterDB = [[HunterDB alloc] init];
	[hunterDB initDB];
	//2. get random mission  (now has ONE mission id=1)
	PicMission *mission = (PicMission *)[[hunterDB findRandomMissions:Mission_Num] objectAtIndex:0];
	//3. init mission view
	CGRect appRect = [[UIScreen mainScreen] applicationFrame];
	missionView = [[MissionView alloc] initWithFrame:appRect];
	[missionView setMission:mission];
	[missionView setRemain:Target_Num];
	[missionView setImage:[UIImage imageNamed:mission.pic]];
	self.view = missionView;
	//3. get random [5] targets
	NSMutableArray *targets = [hunterDB findRandom:Target_Num targetsInMission:mission.missionId];
	[missionView setTargets:targets];
	
	//5.init option views
	CGRect optionFrame = CGRectMake(0, 0, 768, 120);
	scrollView = [[ScrollView alloc] initWithFrame:optionFrame];
	[scrollView setImage:[UIImage imageNamed:@"options.png"]];
	[scrollView setAlpha:0.85];
    [scrollView setTargets:targets];
    [scrollView initButtons];
    [missionView setScrollView:scrollView];
    [self.view addSubview:scrollView];
    //7. init target views
	for (PicTarget *target in targets) {
		CGRect targetFrame = CGRectMake((CGFloat)target.minX, (CGFloat)target.minY, (CGFloat)(target.maxX-target.minX), (CGFloat)(target.maxY-target.minY));
		TargetView *targetView = [[TargetView alloc] initWithFrame:targetFrame];
        //[targetView setImage:[UIImage imageNamed:target.lightPic]];
        [targetView setTarget:target];
		[missionView addSubview:targetView];
	}
    
    UIImage *light_test = [UIImage imageNamed:@"light_test.png"];
    UIImageView *light_view = [[UIImageView alloc] initWithImage:light_test];
    [light_view setFrame:[[UIScreen mainScreen] applicationFrame]];
    [self.view addSubview:light_view];
}



/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end
